package com.xidian.zhiancloud.service.workTicket;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.workTicket.ElectricOperatorMapper;
import com.xidian.zhiancloud.model.workTicket.ElectricOperator;
import com.xidian.zhiancloud.model.workTicket.ElectricTicket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 　　* @program zhiancloud
 * 　　* @author Egoist
 * 　　* @create 2021/5/8 20:41
 *
 */
@Service
public class ElectricOperatorService extends ServiceImpl<ElectricOperatorMapper, ElectricOperator> implements IService<ElectricOperator> {

    @Autowired
    private ElectricService electricService;

    /**
     * 填入作业人信息，返回修改相关信息后的所属作业票
     * @param electricOperator
     * @return 所属作业票
     */
    public ElectricTicket saveOperatorInfo(ElectricOperator electricOperator) {
        save(electricOperator);
        Long ticketId = electricOperator.getTicketId();
        Long operatorId = electricOperator.getId();
        ElectricTicket electricTicket = electricService.getById(ticketId);
        if (electricTicket != null){
            String operatorIds = electricTicket.getOperatorIds();
            if (operatorIds == null || operatorIds.equals(""))
            {
                electricTicket.setOperatorIds(operatorId.toString());
            } else {
                electricTicket.setOperatorIds(operatorIds + "," + operatorId.toString());
            }
        }
        return electricTicket;
    }
}
